package com.healthcloud.thread;


import com.healthcloud.entity.RegionalDisease.*;
import com.healthcloud.service.RegionalDisease.TestprojectitemmonitorService;
import com.healthcloud.utils.SpringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yucl on 2017/12/8.
 */
public class MyThread implements Runnable {

    private static final Logger LOG = LoggerFactory.getLogger(MyThread.class);

    private ChronicGroupEnity entity;
    private String            testKindCode;
    private String            year;
    private String            areaCode;
    private String            level;

    public MyThread(ChronicGroupEnity entity,String testKindCode,String year,String areaCode,String level){
        this.entity = entity;
        this.testKindCode=testKindCode;
        this.year=year;
        this.areaCode=areaCode;
        this.level=level;
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {

        long time = System.currentTimeMillis();
        try {
            TestprojectitemmonitorService testprojectitemmonitorService = SpringUtil.getBeans("testprojectitemmonitorService");
            List<SlowDiseaseStatisticsEntity> slowDiseaseStatisticsEntitys = (testprojectitemmonitorService.showTestItemMonitor(testKindCode, year, Long.valueOf(areaCode), level));
            List<SlowDiseaseStatisticsMsg>  slowDiseaseStatisticsMsgs = new ArrayList<>();

            for(SlowDiseaseStatisticsEntity entity : slowDiseaseStatisticsEntitys){
                List<BodyDiv> bodyDivs = new ArrayList<>();
                SlowDiseaseStatisticsMsg slowDiseaseStatisticsMsg = new SlowDiseaseStatisticsMsg();
                BodyDiv bodyDiv = new BodyDiv();
                GenderDiv genderDiv = new GenderDiv();
                PersonDiv personDiv = new PersonDiv();
                //异常年龄段统计
                bodyDiv.setAgeDistribution(entity.getAgeDistribution());
                //人数和次数统计
                personDiv.setPersonTitle(entity.getPersonTitle());
//                personDiv.setPersonTotalTitle(entity.getPersonTotalTitle());
//                personDiv.setPersonUpperTitle(entity.getPersonUpperTitle());
//                personDiv.setPersonLowerTitle(entity.getPersonLowerTitle());
                personDiv.setPersonTotal(entity.getPersonTotal());
//                personDiv.setPersonUpperTitle(entity.getPersonUpperTitle());
                personDiv.setPersonUpper(entity.getPersonUpper());
                personDiv.setPersonLower(entity.getPersonLower());
                personDiv.setTestTitle(entity.getTestTitle());
//                personDiv.setTestTotalTitle(entity.getTestTotalTitle());
//                personDiv.setTestUpperTitle(entity.getTestUpperTitle());
//                personDiv.setTestLowerTitle(entity.getTestLowerTitle());
                personDiv.setTestTotal(entity.getTestTotal());
                personDiv.setTestUpper(entity.getTestUpper());
                personDiv.setTestUpperPercent(entity.getTestUpperPercent());
                personDiv.setTestLower(entity.getTestLower());
                personDiv.setTestLowerPercent(entity.getTestLowerPercent());
                bodyDiv.setPersonDiv(personDiv);
                //男女统计
                genderDiv.setManCount(entity.getManCount());
                genderDiv.setManPercent(entity.getManPercent());
                genderDiv.setPercentTitle(entity.getPercentTitle());
                genderDiv.setWomanCount(entity.getWomanCount());
                genderDiv.setWomanPercent(entity.getWomanPercent());
                bodyDiv.setGenderDiv(genderDiv);

                bodyDivs.add(bodyDiv);
                slowDiseaseStatisticsMsg.setTitle(entity.getPersonTitle()+"统计");
                slowDiseaseStatisticsMsg.setResultMsg(bodyDivs);
                slowDiseaseStatisticsMsgs.add(slowDiseaseStatisticsMsg);
            }

            entity.setSlowDiseaseStatisticsMsgs(slowDiseaseStatisticsMsgs);

        } catch (Exception e) {
            LOG.error(e.getMessage());
        }finally {
            System.out.println("myThread 运行时间为：" + (System.currentTimeMillis() - time));
        }
    }
}
